<!DOCTYPE html>
<html>
  
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  <meta name="author" content="Amos Zhu">
  
  
  <title>Centos7下安装和配置SonarQube7.7 | Amos的技术博客</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
    <meta name="keywords" content="stuff,centos7,sonarQube7,">
  

  
  <meta name="description" content="IDEA中的代码规范检查很好用，但是不能检测代码的质量，所幸有了SonarQube,我们可以提交代码到git上进行代码质量检测">

  

  
    <script src="//cdn.jsdelivr.net/npm/leancloud-storage@3.11.1/dist/av-min.js" async></script>
  

  
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" async></script>
  

  
    <script src="//unpkg.com/valine/dist/Valine.min.js" async></script>
  

  

  <script>
  // theme-ad's config script
  // it can be used in every script
  
  window.AD_CONFIG = {
    leancloud: {"appid":"eObxCkTJ6j4GzRxGLgiHyfJa-gzGzoHsz","appkey":"fzRMAFC6MCE11mp7mnvh4Kwe","comment":true,"count":true},
    welcome: {"enable":true,"interval":30},
    start_time: "2019-05-28",
    passwords: ["efe07af7441da2b69c4a41e42e73be4db47f66010a56900788a458354a7373ec", ],
    is_post: true,
    lock: false,
    author: "Amos Zhu",
    share: {"qq":true,"wechat":true},
    mathjax: true,
    page_type: "",
    root: "/blog/"
  };
</script>

  <script src="/blog/vendor/sha256.min.js"></script>
<script src="/blog/js/auth.js"></script>
<script src="/blog/js/index.js"></script>
<script src="/blog/vendor/qrcode.min.js"></script>

  
    <link rel="icon" href="/blog/images/favicon.ico">
    <link rel="apple-touch-icon" href="/blog/images/touch-icon.png">
  

  <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

  <link rel="stylesheet" href="/blog/css/index.css">
<link rel="stylesheet" href="/blog/styles/components/highlight/highlight.css">

  
</head>
  <body>
    <header class="site-header">
  <div class="site-header-brand">
    
      <span class="site-header-brand-title">
        <a href="/blog/">Amos Zhu</a>
      </span>
    
    
      <span class="site-header-brand-motto"> | 当浮躁的心静不下，不妨写些东西或者看会书</span>
    
  </div>
  <div class="site-header-right">
    <nav class="site-header-navigation">
      
        <a href="/blog/" target="_self">首页</a>
      
        <a href="/blog/archives/" target="_self">归档</a>
      
        <a href="/blog/tags/" target="_self">标签</a>
      
        <a href="/blog/categories/" target="_self">分类</a>
      
        <a href="/blog/redis/" target="_self">redis</a>
      
        <a href="/blog/rabbitMQ/" target="_self">rabbitMQ</a>
      
        <a href="/blog/elasticsearch" target="_self">elasticsearch</a>
      
        <a href="/blog/stuff" target="_self">stuff</a>
      
        <a href="/blog/kafka" target="_self">kafka</a>
      
        <a href="/blog/friends/" target="_self">友链</a>
      
        <a href="/blog/about/" target="_self">关于</a>
      
    </nav>
    <div class="site-header-btn">
      
        <a href="https://gitee.com/amos_zhu" target="_blank" id="site-github">
          <i class="fa fa-github-alt"></i>
        </a>
      
      <a href="javascript:void(0);" id="site-search">
        <i class="fa fa-search"></i>
      </a>
      <a href="javascript:void(0);" id="site-nav-btn">
        <i class="fa fa-ellipsis-v"></i>
      </a>
    </div>
  </div>
</header>
<nav class="table-content" id="site-nav">
  <div class="table-content-title">
    <span>导航</span>
  </div>
  <div class="table-content-main">
    <ol class="toc">
      
        <li class="toc-item">
          <a href="/blog/" target="_self">
            首页
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/archives/" target="_self">
            归档
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/tags/" target="_self">
            标签
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/categories/" target="_self">
            分类
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/redis/" target="_self">
            redis
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/rabbitMQ/" target="_self">
            rabbitMQ
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/elasticsearch" target="_self">
            elasticsearch
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/stuff" target="_self">
            stuff
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/kafka" target="_self">
            kafka
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/friends/" target="_self">
            友链
          </a>
        </li>
      
        <li class="toc-item">
          <a href="/blog/about/" target="_self">
            关于
          </a>
        </li>
      
    </ol>
  </div>
</nav>
<div id="site-process"></div>
    <main>
      
  <div class="passage">
  <div class="passage-meta">
    <span>
      <i class="fa fa-calendar"></i>2019-07-19
    </span>
    
      <span>
        | <a href="/blog/categories/stuff/"><i class="fa fa-bookmark"></i>stuff</a>
      </span>
    
    
      <span>
        | <i class="fa fa-unlock-alt"></i>UNLOCK
      </span>
    
  </div>
  <h1 class="passage-title">
    Centos7下安装和配置SonarQube7.7
  </h1>
  
  <article class="passage-article">
    <br>为了体验SonarQube,我们先来在Centos7上安装SonarQube运行环境，首先准备sonarQube的安装包,不方便下载的可以使用百度云提供的安装包<p></p>

<p><a href="https://pan.baidu.com/s/1vJYHJKF5Hrhr6rL4MXVSkw" target="_blank" rel="noopener">SonarQube:https://pan.baidu.com/s/1vJYHJKF5Hrhr6rL4MXVSkw</a></p>
<p>提取码：evd1 </p>
<ol>
<li>准备支持环境</li>
</ol>
<p>SonarQube需要Java环境支持，所以我们必须先安装java环境<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">## 查看有没有安装java环境</span></span><br><span class="line">java -version</span><br><span class="line"><span class="comment">## 如果已经安装的跳过此步骤，如果没有安装java的话，centos7中提供yum安装</span></span><br><span class="line">yum install java</span><br><span class="line"><span class="comment">## 查看java的版本（必须是1.8版本的，sonarqube内部的elasticsearch需要jdk1.8支持）</span></span><br><span class="line">java -version</span><br></pre></td></tr></table></figure></p>
<ol start="2">
<li>创建数据库</li>
</ol>
<p>提供Mysql数据库，不在本机也无所谓，sonarQube初次运行时需要在数据库中初始化一些表来存储一些数据，只需要创建数据库即可，sonar自动会为我们创建表<br><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">## 创建sonar数据库，字符集是UTF-8</span></span><br><span class="line"><span class="keyword">create</span> <span class="keyword">database</span> sonar <span class="built_in">character</span> utf8 <span class="keyword">collate</span> utf8_general_ci;</span><br></pre></td></tr></table></figure></p>
<ol start="3">
<li>安装sonarqube<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">## 解压sonarqube7.7</span></span><br><span class="line"><span class="built_in">cd</span> /usr/<span class="built_in">local</span>/</span><br><span class="line">unzip sonarqube-7.7.zip</span><br><span class="line"></span><br><span class="line"><span class="built_in">cd</span> sonarqube-7.7/</span><br><span class="line">ll</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>查看文件如下:<br><img src="https://s2.ax1x.com/2019/07/18/ZO57Y8.png" alt></p>
<p>其中bin文件下是不同的操作文件，conf文件下是配置文件，elasticsearch下是es的相关的配置文件，logs是日志文件</p>
<p>我们需要首先设置sonar的配置文件,添加如下的配置消息：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">## 修改sonar的配置文件</span></span><br><span class="line">vi /usr/<span class="built_in">local</span>/sonarqube-7.7/conf/sonar.properties</span><br></pre></td></tr></table></figure></p>
<p>添加如下的信息<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">sonar.host.url=http://localhost:9090</span><br><span class="line">sonar.jdbc.username=数据库用户名</span><br><span class="line">sonar.jdbc.password=数据库密码</span><br><span class="line">sonar.jdbc.url=jdbc:mysql://数据库IP:3306/sonar?useUnicode=true&amp;characterEncoding=utf8&amp;rewriteBatchedStatements=true&amp;useConfigs=maxPerformance</span><br><span class="line">sonar.web.host=0.0.0.0</span><br><span class="line">## 配置web访问的路径 这里必须要有 / 前缀</span><br><span class="line">sonar.web.context=/sonar</span><br><span class="line">## web容器的端口号</span><br><span class="line">sonar.web.port=9090</span><br></pre></td></tr></table></figure></p>
<p>以上配置就完成了</p>
<ol start="4">
<li>配置elasticsearch启动的准备工作</li>
</ol>
<p>sonarqube内部集成了elasticsearch，而elasticsearch是不能使用root用户启动的，必须是使用普通用户来启动,所以我们先建立普通用户，并且授权<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">## 创建普通用户</span></span><br><span class="line">useradd sonarqube</span><br><span class="line">passwd sonarqube</span><br><span class="line"></span><br><span class="line"><span class="comment">## 给普通用户授sonarqube-7.7的权限</span></span><br><span class="line">chmod -R 777 /usr/<span class="built_in">local</span>/sonarqube-7.7</span><br></pre></td></tr></table></figure></p>
<p>接下来，我们来修改系统相关的配置，以满足elasticsearch启动的需求，如果已经满足了就可以跳过此步骤</p>
<p>elasticsearch需要配置系统相关的参数：具体可以参考官方的文档:</p>
<p><a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-system-settings.html#ulimit" target="_blank" rel="noopener">Configuring system settingsedit</a></p>
<p>具体操作简化如下：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">## 1.max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]</span></span><br><span class="line"></span><br><span class="line"><span class="comment">## 修改/etc/security/limits.conf文件，添加或修改如下行：</span></span><br><span class="line">*        hard    nofile           65536</span><br><span class="line">*        soft    nofile           65536</span><br><span class="line"><span class="comment">## 2.max virtual memory areas vm.max......</span></span><br><span class="line"></span><br><span class="line"><span class="comment">## 修改 /etc/sysctl.conf 文件,添加如下行：</span></span><br><span class="line"></span><br><span class="line">vm.max_map_count=262144</span><br><span class="line"><span class="comment">## 修改好了以后，调用sysctl -a查看，发现参数并没有变动，要重启才可以。</span></span><br></pre></td></tr></table></figure></p>
<p>limits.conf 不需要重启，但是sysctl.conf则需要重启服务器让参数生效，如果服务器不方便重启，也可以通过命令来临时设置变量，只是临时的，服务器重启的话，之前的设置就不会生效了<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">## 命令设置 vm.max_map_count 参数</span></span><br><span class="line">sudo sysctl -w vm.max_map_count=262144</span><br></pre></td></tr></table></figure></p>
<ol start="5">
<li>启动sonarqube</li>
</ol>
<p>至此我们已经全部配置好sonar启动的环境和配置参数，我们来启动sonarqube<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">## 使用普通用户</span></span><br><span class="line">su - sonarqube</span><br><span class="line"></span><br><span class="line"><span class="comment">## 启动sonarqube</span></span><br><span class="line"><span class="built_in">cd</span> /usr/<span class="built_in">local</span>/sonarqube-7.7/bin/linux-x86-64/</span><br><span class="line">./sonar.sh start</span><br><span class="line"></span><br><span class="line"><span class="comment">## 查看sonar状态</span></span><br><span class="line">./sonar.sh status</span><br></pre></td></tr></table></figure></p>
<p>初次启动，需要到数据库中初始化表和数据，所以比较慢，可以随时查看sonar的状态</p>
<ol start="6">
<li>启动失败日志定位问题</li>
</ol>
<p>如果启动失败，依次查看 sonar.log –&gt; es.log –&gt; web.log 日志文件来定位问题</p>
<ol start="7">
<li>访问web页面</li>
</ol>
<p>打开浏览器，访问 <a href="http://SONAR安装的服务器IP:9090/sonar" target="_blank" rel="noopener">http://SONAR安装的服务器IP:9090/sonar</a> 就可以访问</p>
  </article>
  <aside class="table-content" id="site-toc">
  <div class="table-content-title">
    <i class="fa fa-arrow-right fa-lg" id="site-toc-hide-btn"></i>
    <span>目录</span>
  </div>
  <div class="table-content-main">
    
  </div>
</aside>
  
    <aside class="passage-copyright">
      <div>本文作者: Amos Zhu</div>
      
        <div>
          原文链接: 
          <a href target="_blank">http://amos_zhu.gitee.io/passages/Centos7下安装和配置SonarQube7-7/</a>
        </div>
      
      <div>
        版权声明: 本博客所有文章除特别声明外, 均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> 许可协议. 转载请注明出处!
      </div>
    </aside>
  
  
    <div class="passage-tags">
     
      <a href="/blog/tags/centos7/"><i class="fa fa-tags"></i>centos7</a>
     
      <a href="/blog/tags/sonarQube7/"><i class="fa fa-tags"></i>sonarQube7</a>
    
    </div>
  
</div>

    </main>
    
      
<div class="site-comment-contanier" data-plateform="leancloud">
  
    <p id="site-comment-info">
      <i class="fa fa-spinner fa-spin"></i> 评论加载中
    </p>
    <div id="site-comment"></div>
  
</div>
    
    <div class="site-footer-wrapper">
  <footer class="site-footer">
    
      
        <div class="site-footer-col">
          <h5 class="site-footer-title">博客推荐</h5>
          
            <span class="site-footer-item">
              <a href="http://youzhixueyuan.com/series/java" target="_blank">优知学院</a>
            </span>
          
            <span class="site-footer-item">
              <a href="http://ruanyifeng.com/" target="_blank">阮一峰的个人网站</a>
            </span>
          
        </div>
      
        <div class="site-footer-col">
          <h5 class="site-footer-title">系列教程</h5>
          
            <span class="site-footer-item">
              <a href="http://amos_zhu.gitee.io/blog/redis" target="_blank">Redis系列教程</a>
            </span>
          
            <span class="site-footer-item">
              <a href="http://amos_zhu.gitee.io/blog/rabbitMQ/" target="_blank">RabbitMQ教程</a>
            </span>
          
            <span class="site-footer-item">
              <a href="http://amos_zhu.gitee.io/blog/kafka/" target="_blank">Kafka架构探险</a>
            </span>
          
        </div>
      
        <div class="site-footer-col">
          <h5 class="site-footer-title">抓到我</h5>
          
            <span class="site-footer-item">
              <a href="https://gitee.com/amos_zhu" target="_blank">Gitee</a>
            </span>
          
            <span class="site-footer-item">
              <a href="https://blog.csdn.net/wdcl2468" target="_blank">CSDN</a>
            </span>
          
            <span class="site-footer-item">
              <a href="https://www.jianshu.com/u/2dbe61b1f3c3" target="_blank">简书</a>
            </span>
          
        </div>
      
    
    <div class="site-footer-info">
      <i class="fa fa-clock-o"></i> 本站已稳定运行<span id="site-time"></span>
    </div>
    
      <div class="site-footer-info">
        <i class="fa fa-paw"></i> 您是本站第 <span id="site-count"></span> 位访客
      </div>
    
    
      <div class="site-footer-info">
        <i class="fa fa-at"></i> Email: amoszhu@aliyun.com
      </div>
    
    <div class="site-footer-info">
      <i class="fa fa-copyright"></i> 
      2019 <a href="https://github.com/dongyuanxin/theme-ad/" target="_blank">Theme-AD</a>.
      Created by <a href="https://godbmw.com/" target="_blank">GodBMW</a>.
      All rights reserved.
    </div>
  </footer>
</div>
    <div id="site-layer" style="display:none;">
  <div class="site-layer-content">
    <div class="site-layer-header">
      <span class="site-layer-header-title" id="site-layer-title"></span>
      <i class="fa fa-close" id="site-layer-close"></i>
    </div>
    <div class="site-layer-body" id="site-layer-container">
      <div class="site-layer-input" id="site-layer-search" style="display: none;">
        <div class="site-layer-input-choose">
          <a href="javascript:void(0);" title="Change Search Engine">Google</a>
        </div>
        <input type="text">
        <i class="fa fa-search"></i>
      </div>
      
        <div class="site-layer-reward" id="site-layer-reward" style="display: none;">
          
            <div>
              <img src="/blog/images/wechat.png" alt="WeChat">
              
                <p>WeChat</p>
              
            </div>
          
            <div>
              <img src="/blog/images/alipay.png" alt="AliPay">
              
                <p>AliPay</p>
              
            </div>
          
        </div>
      
      <div id="site-layer-welcome" style="display:none;"></div>
    </div>
  </div>
</div>
    

<div class="bottom-bar">
  <div class="bottom-bar-left">
    <a href="/blog/passages/面试那点事儿（二）/" data-enable="true">
      <i class="fa fa-arrow-left"></i>
    </a>
    <a href="/blog/passages/RabbitMQ面试那点事儿/" data-enable="true">
      <i class="fa fa-arrow-right"></i>
    </a>
  </div>
  <div class="bottom-bar-right">
    <a href="javascript:void(0);" data-enable="true" id="site-toc-show-btn">
      <i class="fa fa-bars"></i>
    </a>
    
      <a href="#site-comment" data-enable="true">
        <i class="fa fa-commenting"></i>
      </a>
    
    <a href="javascript:void(0);" id="site-toggle-share-btn">
      <i class="fa fa-share-alt"></i>
    </a>
    
      <a href="javascript:void(0);" id="site-reward">
        <i class="fa fa-thumbs-up"></i>
      </a>
    
    <a href="javascript:void(0);" id="back-top-btn">
      <i class="fa fa-chevron-up"></i>
    </a>
  </div>
</div>
    <div id="share-btn">
  
  
  
  
    <a id="share-btn-qq" href="javascript:void(0);" target="_blank">
      <i class="fa fa-qq"></i>
    </a>
  
  
    <a id="share-btn-wechat" href="javascript:void(0);" target="_blank">
      <i class="fa fa-wechat"></i>
    </a>
  
</div>
    


  <script async>
  (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      if (curProtocol === 'https') {
          bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
      }
      else {
          bp.src = 'http://push.zhanzhang.baidu.com/push.js';
      }
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
  })();
  </script>



  <script async>
    (function(){
    var src = (document.location.protocol == "http:") ? "http://js.passport.qihucdn.com/11.0.1.js?":"https://jspassport.ssl.qhimg.com/11.0.1.js?";
    document.write('<script src="' + src + '" id="sozz"><\/script>');
    })();
  </script>


    
  </body>
</html>